package com.saibo.webdriver.core;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class PhantomJS {
	DesiredCapabilities desiredCapabilities;
	PhantomJSDriver driver;

	public PhantomJS() {
		System.setProperty("phantomjs.binary.path", "E:\\phantomjs\\phantomjs.exe");
		desiredCapabilities = DesiredCapabilities.phantomjs();
		desiredCapabilities.setJavascriptEnabled(true);  
		driver = new PhantomJSDriver(desiredCapabilities);
	}
	
	public String connect(String url){
		driver.get(url);
		driver.manage().timeouts().setScriptTimeout(15, TimeUnit.SECONDS);
		WebElement s =driver.findElement(By.xpath("//*[@id=\"F0\"]/div[2]/div[2]/div[1]/div/div[2]/span[1]"));
		System.out.println(s);
		
		
		
		System.out.println("Title:"+driver.getTitle());
		return driver.getPageSource();
	}
	
	public void close(){
		driver.quit();
	}
	
}
